<?php
namespace Admin\Controller;
use Think\Controller;
class MemberController extends CommonController {

	public function _initialize(){
	parent::_initialize();
	$this->model="member";
	$this->key="id";	
	$this->title_index= L('index');
	$this->title_details=L('details');
	}
	
	//保存
	public function updateHandle(){
		$oop=M($this->model);
		$oop->create();
		$oop->salt=makePass(20);//密码加盐值	
		if(I('new_pwd'))
			$oop->password=md5(I('new_pwd').$oop->salt);	
		if($oop->save())
			$this->success(L("update_success"));
		else
			$this->error(L("update_failed"));		
	}

	public function addHandle(){
		$oop=M($this->model);
		$oop->create();
		$oop->salt=makePass(20);//密码加盐值
		$oop->password=md5(I('new_pwd').$oop->salt);
		if($oop->add())
			$this->success(L("add_success"));
		else
			$this->error(L("add_failed"));				
	}
	
	//删除
	public function deleteHandle(){
		if(in_array(I($this->key),C("AUTH_CONFIG.AUTH_ADMIN")))
			$this->error(L("admin_not_delete"));
		parent::deleteHandle();
	}
	
	//分配管理组
	public function assignRole(){
		$oop=M('authGroupAccess');
		$con['uid']=I('uid');
		$oop->where($con)->delete();
		$oop->create();
		if($oop->add())
			$this->success(L("assign_success"));
		else
			$this->error(L("assign_failed"));
	}
	
}